/**
 * Created on 2007-03-06 23:47
 */
package game.media.gfx;

import java.awt.Color;

/**
 * @author David Wallin
 */
public class SquareEntity extends Entity
{
	/**
	 * The color of this square entity
	 */
	private Color						m_Color;
	/**
	 * This block's normal state
	 */
	private BlockStateNormal			m_StateNormal;
	/**
	 * This block's highlighted state
	 */
	private BlockStateHighlighted		m_StateHighlighted;
	/**
	 * The current state of the block
	 */
	private BlockState					m_State;
	/**
	 * Whether or not this block is a game block
	 */
	private boolean						m_IsGameBlock;
	
	/**
	 * Constructor, calls super, initializes members
	 * 
	 * @param xpos the x cordinate of this entity
	 * @param ypos the y cordinate of this entity
	 * @param width the width of this entity
	 * @param height the height of this entity
	 * @param color the color of this entity
	 */
	public SquareEntity(int xpos, int ypos, int width, int height, Color color, boolean isGameBlock)
	{
		super(xpos, ypos, width, height);
		
		m_Color = color;
		m_StateNormal = new BlockStateNormal(this);
		m_StateHighlighted = new BlockStateHighlighted(this, m_Color);
		m_State = m_StateNormal;
		m_IsGameBlock = isGameBlock;
	}
	
	/**
	 * Sets the current state of this entity
	 * 
	 * @param state the state to set
	 */
	public void setState(BlockState state)
	{
		m_State = state;
	}
	
	/**
	 * Gets this entity's normal state
	 * 
	 * @return the normal state of this entity
	 */
	public BlockState getNormalState()
	{
		return m_StateNormal;
	}
	
	/**
	 * Gets this entity's highlighted state
	 * 
	 * @return the highlighted state of this entity
	 */
	public BlockState getHighlightedState()
	{
		return m_StateHighlighted;
	}
	
	/* (non-Javadoc)
	 * @see game.Entity#draw()
	 */
	@Override
	protected void doDraw()
	{
		//m_RenderManager.drawSquare(getXpos(), getYpos(), getWidth(), getHeight(), m_Color);
		m_State.draw(m_Color);
		
		if(m_IsGameBlock)
		{
			m_RenderManager.setCurrentColor(Color.black);
			m_RenderManager.drawRect(this.getXpos(), this.getYpos(), this.getWidth(), this.getHeight());
			m_RenderManager.drawRect(this.getXpos() + 1, this.getYpos() + 1, this.getWidth() - 2, this.getHeight() - 2);
			
			m_RenderManager.drawLine(this.getXpos() + 2, this.getYpos() + 3, this.getXpos() + 2, this.getYpos() + this.getHeight() - 2);
			m_RenderManager.drawLine(this.getXpos() + 3, this.getYpos() + 5, this.getXpos() + 3, this.getYpos() + this.getHeight() - 3);
			m_RenderManager.drawLine(this.getXpos() + 2, this.getYpos() + this.getHeight() - 2, this.getXpos() + this.getWidth() - 3, this.getYpos() + this.getHeight() - 2);
			m_RenderManager.drawLine(this.getXpos() + 2, this.getYpos() + this.getHeight() - 3, this.getXpos() + this.getWidth() - 5, this.getYpos() + this.getHeight() - 3);
		}
	}
}
